<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Payment_model extends CI_Model {

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    function add_payment($_POST){
		$this->db->query("INSERT INTO payment_info VALUES (
			'".$_POST["student_number"]."',
			'".$_POST["or_number"]."',
			'".$_POST["from_period"]."',
			'".$_POST["to_period"]."',
			'".$_POST["type"]."',
			'".$_POST["amount"]."',
			'".$_POST["date_paid"]."',
			'".$_POST["remark"]."'
			)");
	}
	
	function check_payment($_POST){
		$query = $this->db->query("
			SELECT * FROM payment_info 
			WHERE student_number='".$_POST["student_number"]."'
			and or_number='".$_POST["or_number"]."'
			and type='".$_POST["type"]."'");
		return $query->num_rows()>0?1:0;
	}
	
	function get_payment($_POST){
		return $this->db->query("
			SELECT * FROM payment_info 
			WHERE student_number='".$_POST["student_number"]."'
			and or_number='".$_POST["or_number"]."'
			and type='".$_POST["type"]."'");
	}
	
	function get_payments($_POST){
		return $this->db->query("
			SELECT * FROM payment_info 
			WHERE student_number='".$_POST["student_number"]."'");
	}
	
	function edit_payment($_POST){
		$this->db->query("UPDATE payment_info SET
			from_period='".$_POST["from_period"]."',
			to_period='".$_POST["to_period"]."',
			amount='".$_POST["amount"]."',
			date_paid='".$_POST["date_paid"]."',	
			remark='".$_POST["remark"]."'
			WHERE student_number='".$_POST["student_number"]."' 
			and or_number='".$_POST["or_number"]."'
			and type='".$_POST["type"]."'
			");
	}
	
	function delete_payment($_POST){
		$this->db->query("DELETE FROM payment_info 
		WHERE student_number='".$_POST["student_number"]."' 
		and or_number='".$_POST["choice"]."'
		and type='".$_POST["type_hidden"]."'
		");
	}

}
/* End of file payment_model.php */
/* Location: ./application/models/payment_model.php */
?>